package com.google.code.openperfmon.web.admin;

import java.util.List;

import com.google.code.openperfmon.domain.AppUser;
import com.google.code.openperfmon.service.AdminEntityInfo;
import com.google.code.openperfmon.service.ReferenceExistException;
import com.google.code.openperfmon.service.ServiceFactory;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ManageUsersAction extends ActionSupport {	 
	private Long id;
	private List<AdminEntityInfo<AppUser>> users;
	
	public String list() throws Exception {
		users = ServiceFactory.getUserService().listUsers(); 
		return SUCCESS;
	}

	public String delete() throws Exception {
		try {
			ServiceFactory.getUserService().deleteUser(id);
		}
		catch (ReferenceExistException e) {
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public List<AdminEntityInfo<AppUser>> getUsers() {
		return users;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}
